//
//  NetworkClient.h
//  NetworkDemo
//
//  Created by 万孟超 on 2021/9/7.
//

#import <Foundation/Foundation.h>
#import "NetworkRetryModel.h"

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSInteger, NetworkTaskState) {
    NetworkTaskStateFail = 0,
    NetworkTaskStateSuccess,
    NetworkTaskStatePending,
    NetworkTaskStateNone
};

@interface NetworkClient : NSObject

/**
 单例初始化方法
 */
+ (instancetype)sharedManager;

/// 记录需要重试的请求任务
/// @param retryModel 重试的Model
- (void)addRetryModel:(NetworkRetryModel *)retryModel;

/// 记录请求超时需要重试的请求任务
/// @param retryModel 重试的Model
- (void)addTimeoutRetryModel:(NetworkRetryModel *)retryModel;

/// 记录请求任务
/// @param engineTask 请求引擎任务
/// @param enginePoint 引擎内存地址
- (void)setEngineTask:(NSURLSessionTask *)engineTask forEnginePoint:(NSString *)enginePoint;

/// 取消请求任务
/// @param enginePoint 引擎内存地址
- (void)cancelEngineNetworkTaskWithPoint:(NSString *)enginePoint;

/// 移除请求任务->用于网络请求成功之后自动移除
/// @param enginePoint 引擎内存地址
/// @param isSuccess 接口是否成功
- (void)removeEngineNetworkTaskWithPoint:(NSString *)enginePoint isSuccess:(BOOL)isSuccess;

/// 查询接口是否正在请求
/// @param method 查询的接口方法名
/// @param isWait 是否等待接口完成才回调
/// @param completeBlock 结果
- (void)searchNetwork:(NSString *)method waitUntilNetworkComplete:(BOOL)isWait methodCompleteBlock:(void(^)(BOOL isRunning, NetworkTaskState taskState))completeBlock;

/// 等待接口都请求完成->必须在主线程调用，子线程调用运行内存会崩掉，我也不知道为什么
/// @param completeBlock 完成回调 (0:失败 1:成功 3:没请求？)
/// @param method 接口列表
- (void)waiteNetworkSuccessWithBlock:(void(^)(NSDictionary<NSString *, NSNumber *> * __nullable result))completeBlock methodKeys:(nonnull NSString *)method, ... NS_REQUIRES_NIL_TERMINATION;   

@end

NS_ASSUME_NONNULL_END
